<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="common/common_head :: commonHeader('非生产性分批发货')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
</head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
		<div class="col-sm-12 search-condition">
			<form id="orderItemForm" th:action="@{/orderItem/list}" class="form-inline">
				<div class="select-list">
					    <ul>
						    <!--<li class="col-sm-3">
							<label>采购凭证号：</label>
							<input type="text" name="poNo" style="width:50%" />
							</li>
							<li class="col-sm-3">
							<label>订单类型：</label>
							    <select name="poType" sysDict="CGDDLX" emptyFirst="true" style="width:50%"></select>
							</li>
							<li class="col-sm-3">
							<label style="width:120px">供应商SAP编码：</label>
							    <input type="text" name="sapCode" style="width:50%" />
							</li>
							<li class="col-sm-3">
							<label>采购组：</label>
							    <select name="purchGroup" sysDict="CGZ" emptyFirst="true" style="width:50%"></select>
							</li>
							<li class="col-sm-3">
							<label>物料编码：</label>
							    <input type="text" name="materialCode" style="width:50%" />
							</li>
							<li class="col-sm-3">
							<label style="width:120px">供应商SRM编码：</label>
							    <input type="text" name="srmCode" style="width:50%" />
							</li>-->
							<li class="col-sm-3">
							<input type="hidden" id="ids" name="ids" th:value="${ids}" />
							<input type="hidden" id="status" name="status" th:value="${status}" />
							<!--<button id="orderItemSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
							<button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>-->
							</li>
						</ul>
				</div>
			</form>
		</div>
	    <div class="col-sm-12 select-info order-table">
			<div class="btn-group hidden-xs toolbar" id="orderItemToolBar" role="group">
				 <a class="btn btn-outline btn-success btn-rounded" onclick="save()">
						<i class="fa fa-save"></i> 分批发货
				 </a>
			</div>
			<table id="orderItem" data-mobile-responsive="true"></table>
		</div>
    </div>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<script type="text/javascript">

	/**
	分批发货
	*/
	var searcherBS = Searcher.createBS('#orderItem',
	[
		{title: '物料编码', field:'materialCode'},
		{title: '物料描述', field:'materialDesc'},
		{title: '采购凭证号', field:'poNo'},
		{title: '订单确认状态', field:'itemStatus'},
		{title: '行项目号', field:'itemNo'},
		{title: '采购订单数量', field:'poCount'},
		{title: '已发货数量', field:'shippedQty',
			formatter: function(value,row,index,field){
				if(!value){
					value=0;
				}
			return value;
			}
		},
		{title: '本次发货数量', field:'dueOut',
			formatter: function(value,row,index,field){
				if(!row.shippedQty){
					row.shippedQty=0;
				}
	             return '<input onchange="change(ipt' + row.poItemId +','+(row.poCount-row.shippedQty)+')" type="text" name="dueOut" size="6" id="ipt' + row.poItemId +'" min="0" max="'+(row.poCount-row.shippedQty)+'" value="'+(row.poCount-row.shippedQty)+'" />';
	       }
		}
	], {pageList: [10], pageSize : 10, showColumns: false, clickToSelect: false, showRefresh: false}
	);
    
    /**
     * 查询数据
     */
    function refresh() {
    	searcherBS.refresh();
    }
    
    $(function () {
    	initDictDataSel();//初始化所有字典数据
    });
    /**
     * 数据校验
     */
    function change(id,dueOut) {
    	  //得到输入的值
    	  var str=id.value;
  	  if(dueOut<str){
  	    	  alert("请输入小于待发货的量");
  	    	  $(id).val("");
  	  }
  	  if(str<=0){
  	    	  alert("请输入正确的发货量");
  	    	  $(id).val("");
  	  }
    }
    /**
     * 保存
     */
     function save() {
 		var myMap = {};
     	var ss=$("#ids").val().split(",");
        for (var i = 0; i <ss.length; i++){
             myMap[ss[i]] = $("#ipt"+ss[i]).val();
        }
        var json={"ids":myMap};
     	Page.ajaxPOST(ctxPath + "/orderItem/save",JSON.stringify(json), function () {
             Dialog.msg("操作成功", function () {
             	parent.refresh();
             	Dialog.closeFrame(window.name);
             });
         }, {contentType : "application/json", "loadingMsg" : "正在往服务器提交数据……"});
      }
</script>
</body>
</html>